package com.tianma315.admin.qa.controller;


import java.util.Arrays;

import com.tianma315.admin.common.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.qa.domain.GlassBottleLineDO;
import com.tianma315.admin.qa.service.GlassBottleLineService;

/**
 * 
 * <pre>
 * 玻璃瓶线
 * </pre>
 * <small> 2019-07-10 09:48:55 | wen</small>
 */
@Controller
@RequestMapping("/qa/glassBottleLine")
public class GlassBottleLineController {
	@Autowired
	private GlassBottleLineService glassBottleLineService;
	
	@GetMapping()
	@RequiresPermissions("qa:glassBottleLine:glassBottleLine")
	String GlassBottleLine(){
	    return "qa/glassBottleLine/glassBottleLine";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("qa:glassBottleLine:glassBottleLine")
	public Result<Page<GlassBottleLineDO>> list(Integer pageNumber, Integer pageSize, GlassBottleLineDO glassBottleLineDTO){
		// 查询列表数据
        Page<GlassBottleLineDO> page = new Page<>(pageNumber, pageSize);
        
        Wrapper<GlassBottleLineDO> wrapper = new EntityWrapper<GlassBottleLineDO>(glassBottleLineDTO);
        page = glassBottleLineService.selectPage(page, wrapper);
        int total = glassBottleLineService.selectCount(wrapper);
        page.setTotal(total);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("qa:glassBottleLine:add")
	String add(){
	    return "qa/glassBottleLine/add";
	}

	@GetMapping("/edit/{glassBottleLineId}")
	@RequiresPermissions("qa:glassBottleLine:edit")
	String edit(@PathVariable("glassBottleLineId") Integer glassBottleLineId,Model model){
		GlassBottleLineDO glassBottleLine = glassBottleLineService.selectById(glassBottleLineId);
		model.addAttribute("glassBottleLine", glassBottleLine);
	    return "qa/glassBottleLine/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("qa:glassBottleLine:add")
	public Result<String> save( GlassBottleLineDO glassBottleLine){
		if(glassBottleLineService.insert(glassBottleLine)){
			return Result.ok();
		}
		return Result.fail();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("qa:glassBottleLine:edit")
	public Result<String>  update( GlassBottleLineDO glassBottleLine){
		glassBottleLineService.updateById(glassBottleLine);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("qa:glassBottleLine:remove")
	public Result<String>  remove( Integer glassBottleLineId){
		if(glassBottleLineService.deleteById(glassBottleLineId)){
            return Result.ok();
		}
		return Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("qa:glassBottleLine:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] glassBottleLineIds){
		glassBottleLineService.deleteBatchIds(Arrays.asList(glassBottleLineIds));
		return Result.ok();
	}
	
}
